package com.hao.shirojwt.config;

import com.hao.shirojwt.interceptor.WhiteListInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;


@Configuration
public class MyWebMvcConfigurer extends WebMvcConfigurationSupport {

    // 全局拦截ip白名单
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new WhiteListInterceptor()).addPathPatterns("/**");
    }

    // 支持跨域访问
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**");
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/webapp/**").addResourceLocations("classpath:/webapp/");
        registry.addResourceHandler("/webapp2/**").addResourceLocations("classpath:/webapp2/");
    }

}